﻿layui.use(function () {
    var upload = layui.upload;
    var layer = layui.layer;
    var element = layui.element;
    var $ = layui.$;
    var laydate = layui.laydate;
    var form = layui.form;
    var table = layui.table;
  
    window.XiangBackfill = function XiangBackfill() {
        var QualityScheme = $("#QualityScheme").val()
        console.log(QualityScheme)
        // 先进行表格的初始渲染
        table.render({
            elem: '#carriertable',  // 表格元素的选择器
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { type: 'checkbox', fixed: 'left' },
                { field: 'qualityinspectionName', title: '质检项目名称' },
                { field: 'qualityinspectionBH', title: '质检项目编号' },
                { field: 'qualityinspectionmethood', title: '质检方法' },
                { field: 'qualityinspectiontool', title: '质检工具' },
                { field: 'qualityinspectionmetype', title: '质检类型' },
                { field: 'standardvalue', title: '标准值' },
                { field: 'createdDate', title: '创建时间' },
                { field: 'createdBy', title: '创建人' },
                { field: 'remark', title: '备注' },
              
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });

        $.ajax({
            url: '../Quality/QualitySpectionFanDo',
            type: 'get',
            data: {
                QualityPlanName: QualityScheme,
                token:""
            },
            //contentType: 'application/json',
            success: function (res) {
           var res = JSON.parse(res)
                console.log(res)
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('carriertable', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: res.data
                });

            }
        })
    }
 window.DeviceAdd = function DeviceAdd() {
        QualityNumber = $("#QualityNumber").val()
        QualityName = $("#QualityName").val()
        QualityTime = $("#QualityTime").val()
        Qualityer = $("#Qualityer").val()
        Supplier = $("#Supplier").val()
        MaterialNumber = $("#MaterialNumber").val()
        MaterialName = $("#MaterialName").val()
        Unit = $("#Unit").val()
        SpecificationsModel = $("#SpecificationsModel").val()
        batchNumber = $("#batchNumber").val()
        Size = $("#Size").val()
        QualityType = $("#QualityType").val()
        QualityScheme = $("#QualityScheme").val()
     QualityS = $("[name='QualityS']:checked").val()
       QualityNum = $("#QualityNum").val()
     AcceptanceQuantity = $("#AcceptanceQuantity").val()
     UnqualifiedQuantity = $("#UnqualifiedQuantity").val()
     QualityInspector = $("#QualityInspector").val()
     Remark = $("#Remark").val()
     QualityResult = $("#QualityResult").val()

     console.log(QualityNum)
     console.log(AcceptanceQuantity)
     console.log(UnqualifiedQuantity)
     console.log(QualityInspector)
     console.log(Remark)
     console.log(QualityResult)


   
   // 取质检项目id
        var checkStatus = table.checkStatus('carriertable');
        var selectedIds = checkStatus.data.map(function (item) { return item.qualityinspectionId; });
        console.log(selectedIds)
        $.ajax({
            url: '../Quality/AddTianRawMATER',
            type: 'post',
            data: {
                QualityNumber: QualityNumber,
                QualityName: QualityName,
                QualityTime: QualityTime,
                Qualityer: Qualityer,
                Supplier: Supplier,
                MaterialNumber: MaterialNumber,
                MaterialName: MaterialName,
                Unit: Unit,
                SpecificationsModel: SpecificationsModel, 
                batchNumber: batchNumber,
                Size: Size,
                QualityType: QualityType,
                QualityScheme: QualityScheme,
                QualityS: QualityS,
                qualityinspectionId: selectedIds,
                QualityNum: QualityNum,
                AcceptanceQuantity: AcceptanceQuantity,
                UnqualifiedQuantity: UnqualifiedQuantity,
                QualityInspector:QualityInspector,
                Remark: Remark,
                QualityResult: QualityResult
   },
            //contentType: 'application/json',
            success: function (res) {
                console.log(res)
                var res = JSON.parse(res)
                if (res.data > 0) {
                    alert("添加成功")
                    window.location.href = '/Quality/MaterialTable'
                }
                else {
                    alert("添加失败")
                }

            }
        })

    }


})